@extends("admin.layouts.main")
<style>
    .card-body .form-group {
        width: 25%;
    }
</style>
@section("content")
<div class="container-fiuld p-3">
    <div class="card">
        <div class="card-header bg-transparent border-0">
            <h2>修改密码</h2>
        </div>
        <div class="card-body">
            <div>
                <form>
                    <div class="form-group">
                        <label for="oldpwd">原始密码:</label>
                        <input type="password" class="form-control" id="oldpwd" name="oldpwd" placeholder="原始密码">
                    </div>
                    <div class="form-group">
                        <label for="newpwd">新密码:</label>
                        <input type="password" class="form-control" id="newpwd" name="newpwd" placeholder="新密码">
                    </div>
                    <div class="form-group">
                        <label for="quepwd">再次确认:</label>
                        <input type="password" class="form-control" id="quepwd" name="quepwd" placeholder="再次确定新密码">
                    </div>
                    <div class="form-group">
                        <input type="button" class="form-control" value="确认" lay-submit lay-filter="addAgent">
                    </div>
                </form>
            </div>
            <div class="card-footer bg-transparent border-0">
            </div>
        </div>
    </div>
</div>
@endsection
@section("js")
<script>
    //数据操作
    layui.use(["form", "layer"], function () {
        var form = layui.form, $ = layui.$, layer = layui.layer;
        //获取下面表单的ID
        form.on('submit(addAgent)', function (data) {
            var oldpwd = $('#oldpwd').val();
            var newpwd = $('#newpwd').val();
            var quepwd = $("#quepwd").val();
            if (newpwd != quepwd) {
                layer.msg('密码不相等', {icon: 1});
            }
            $.ajax({
                url: "{{ route('edit_save') }}",
                type: "POST",
                data: {
                    oldpwd: oldpwd,
                    newpwd: newpwd,
                    quepwd: quepwd
                },
                dataType: "json",
                crossDomain: true,
                success: function (res) {
                    if (res.code == 0) {						
                        //layer.msg('修改成功', {icon: 1});
                        //window.location.href = "{{ route('agent/logout') }}"
                        layer.msg('修改成功,3秒后退出，请重新登录', {icon: 1});
						setTimeout(function(){
                            top.location.href = "{{ route('agent/logout') }}";
                        }, 3000 );


                    } else {
                        layer.msg(res.exception, {icon: 1});
                    }
                },
                error: function (err) {
                    layer.msg('提交失败', {icon: 5});
                    $(".btn.btn-primary").html("提交")
                    console.log(err)
                }
            })
            return false;
        })
    })
</script>
@endsection
